package DAO;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import Beans.CajaBean;
import HibernateUtils.HibernateUtil;

public class HibernateCajaDAO {
	private static HibernateCajaDAO instancia;
	private static SessionFactory sf;

	public static HibernateCajaDAO getInstancia(){
		if(instancia==null){
			sf=HibernateUtil.getSessionFactory();
			instancia=new HibernateCajaDAO();
		}
		return instancia;
	}
	
	

	public CajaBean buscarCaja(CajaBean ab) {
		Session session=sf.openSession();
		CajaBean caja=(CajaBean) session.get(CajaBean.class,ab.getIdCaja());
		session.close();
		return caja;
	}

	public List<CajaBean> getCajas(int idSucursal) {
		Session session=sf.openSession();
		List<CajaBean>cajas=session.createQuery("from CajaBean a where a.idCaja=?").setInteger(0, idSucursal).list();
		return cajas;
	}
}
